home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / COPYTREE.C < prev    next >
Text File  |  1992-12-02  |  5KB  |  153 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  */
  55.  
  56. #include    "SystemPub.h"
  57. #include    "Proc.h"
  58. #include    "Path.h"
  59. #include    "ShellPub.h"
  60.  
  61. /*******************************************************************/
  62.  
  63. void        CopyTree( WHandle ShellWh, int16 ProcID, char *dir1, char *dir2 )
  64. {
  65. int16        srcVref, dstVref, err;
  66. int32        srcDirID, dstDirID, srcParID, temp;
  67. pathType    pt;
  68. char        sName[ 64 ], dName[ 64 ], *dir;
  69.  
  70.     pt = SetCurrPath( dir1 );
  71.     if( pt == pathIsDir )
  72.         {
  73.         strcpy( sName, GetLastScan() );
  74.         GetPWDInfo( &srcVref, &srcDirID, &srcParID );
  75.         ResetShellPWD( ShellWh );
  76.  
  77.         pt = SetCurrPath( dir2 );
  78.         if( pt != pathIsFile )
  79.             {
  80.             GetPWDInfo( &dstVref, &dstDirID, &temp );
  81.  
  82.             if( pt == pathIsDir )        /* dir exists, fail */
  83.                 procPrintf( ShellWh, ProcID, "cpt : can't overwrite %s (%d).\n", dir2, err );
  84.             else    /* does not exist, use given name */
  85.                 {
  86.                 dir = ExtractFile( dir2 );
  87.                 strcpy( dName, dir );
  88.  
  89.                 err = CopyDir( sName, dName, srcVref, dstVref, srcParID, dstDirID );
  90.                 if( err )
  91.                     procPrintf( ShellWh, ProcID, "cpt : can't copy %s (%d).\n", dir1, err );
  92.                 }
  93.             }
  94.         else
  95.             procPrintf( ShellWh, ProcID, "cpt : can't copy directory to file %s.\n", sName );
  96.         }
  97.     else
  98.         procPrintf( ShellWh, ProcID, "cpt : %s not a directory.\n", dir1 );
  99.  
  100.     ResetShellPWD( ShellWh );
  101. }
  102.  
  103. /*******************************************************************/
  104.  
  105. Boolean            DoCPT( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
  106. {
  107. int16            i, argc;
  108. char            *cp, dir1[ 256 ], dir2[ 256 ];
  109. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  110.  
  111.     switch( ProcToken )
  112.         {
  113.         case    PROC_INIT    :
  114.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  115.             break;
  116.             
  117.         case    PROC_TERM    :
  118.         case    PROC_BREAK    :
  119.             /* Tell the shell that we're done */
  120.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  121.             /* Turn ourself off */
  122.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  123.             break;
  124.             
  125.         case    PROC_STDIN    :
  126.             if( (**MyShell).Proc[ ProcID ].flags )
  127.                 {
  128.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  129.  
  130.                 /* get arguments */
  131.                 argc = (**MyShell).Proc[ ProcID ].argc;
  132.                 
  133.                 if( argc == 3 )
  134.                     {
  135.                     GetArgv( ShellWh, ProcID, 1, dir1 );
  136.                     GetArgv( ShellWh, ProcID, 2, dir2 );
  137.                     CopyTree( ShellWh, ProcID, dir1, dir2 );
  138.                     ResetShellPWD( ShellWh );
  139.                     }
  140.                 else
  141.                     procPrintf( ShellWh, ProcID, 
  142.                         "cpt : incorrect number of arguments\n" );
  143.  
  144.                 /* Tell the shell that we're done */
  145.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  146.                 
  147.                 /* Turn ourself off */
  148.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  149.                 return( FALSE );
  150.                 }
  151.         }
  152. }
  153.